home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / AIFF DSP v22 / plugin_src / view.c < prev    next >
Text File  |  1995-01-30  |  2KB  |  93 lines

  1. /* displays the waveform in an AIFF file. */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <limits.h>
  6. #ifdef THINK_C
  7. #include <console.h>
  8. #endif
  9.  
  10. #include "plugin_specific.h"
  11. #include "aiff.h"
  12.  
  13. static FILE *tmpfil;
  14.  
  15. void init_process_view( void ) {
  16.    if ( nh.wdsi != 8 && nh.wdsi != 16 )
  17.       err( "Cannot process a file with this word size" );
  18.    if ( (nh.chan != 1) )
  19.       err( "Cannot process a multichannel file" );
  20.    if ( USHRT_MAX != 65535 )
  21.       err( "this plugin is based on the assumption of 2 byte shorts" );
  22.    
  23.    tmpfil = tmpfile();
  24. }
  25.  
  26. void process_samdat_view( long buflen ) {
  27.    fwrite( d, buflen*nh.framsiz, 1, tmpfil );
  28. }
  29.  
  30. #define ROWS    23
  31. #define TOTCOLS 80
  32. #define COLS    TOTCOLS-7
  33. #define TOTROWS ROWS+1
  34.  
  35. static char s[(TOTCOLS+1)*TOTROWS+1] = "", *tmps;
  36.  
  37. void samstr_view( short samval ) {
  38.    static char spaces[COLS+1] = "";
  39.    int col_i;
  40.    
  41.    if ( !*spaces ) memset( spaces, ' ', COLS );
  42.    
  43. #define WS nh.wdsi
  44.    col_i = (samval+(1L<<(WS-1))) * (COLS+1) / (1L<<WS);
  45.  
  46.    sprintf( tmps, "%6d%.*s|\n", samval, col_i, spaces );
  47.    tmps += col_i + 8;
  48. }
  49.  
  50. void term_process_view ( void ) {
  51.    char c, *tbuf_char;
  52.    short buf[ROWS], *tbuf_short, i, ofs = 0;
  53.  
  54. #ifdef THINK_C
  55.    csetmode( C_CBREAK, stdin );
  56. #endif
  57.    fseek( tmpfil, 0, SEEK_SET );
  58.    
  59.    do {
  60.       fseek( tmpfil, ofs * nh.framsiz, SEEK_CUR );
  61.       fread( buf, ROWS * nh.framsiz, 1, tmpfil );
  62. #ifdef THINK_C
  63.       cgotoxy( 1, 1, stdout );
  64.       ccleos( stdout );
  65. #endif
  66.       tmps = s;
  67.  
  68.       if ( nh.framsiz == 2 )
  69.          for (i=0, tbuf_short=buf; i<ROWS; i++) samstr_view( *tbuf_short++ );
  70.       else
  71.          for (i=0, tbuf_char=(char *) buf; i<ROWS; i++)
  72.             samstr_view( *tbuf_char++ );
  73.  
  74.       fprintf( stderr, "%sfile pos: %ld (d/u line, f/b screen, x exit) ",
  75.                s, ftell( tmpfil ) );
  76.       
  77.       c = getchar();
  78. #ifndef THINK_C
  79.       getchar();
  80. #endif
  81.       ofs = -ROWS + (( c == 'b' ) ? -ROWS : 
  82.                      ( c == 'f' ) ?  ROWS :
  83.                      ( c == 'r' ) ? -10*ROWS :
  84.                      ( c == 'l' ) ?  10*ROWS :
  85.                      ( c == 'u' ) ? -1 :
  86.                      ( c == 'd' ) ?  1 : 0 );
  87.    } while ( c != 'x' );
  88.    
  89.    fclose( tmpfil );
  90. }
  91. plugin_info plugin_view = { init_process_view,
  92.    term_process_view, process_samdat_view, 1, 0 };
  93.